package com.wecan.saasdata.controller;

import com.wecan.api.saasdata.OssData;
import com.wecan.base.PO.Oss;
import com.wecan.base.constants.CommonConstants;
import com.wecan.base.controller.BaseController;
import com.wecan.saasdata.mapper.OssMapper;
import com.wecan.saasdata.service.OssService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author liuzhihao
 * @Date 2022.01.15
 * @Version 1.0.0
 * @Description oss数据层服务
 */
@RestController
@RequestMapping(value = "/oss")
public class OssController extends BaseController implements OssData {

    @Autowired
    OssMapper ossMapper;

    @Autowired
    OssService ossService;

    @Override
    public boolean insert(Oss oss) {
        int result = ossMapper.insert(oss);
        return result > 0;
    }

    @Override
    public boolean delete(Long id) {
        int result = ossMapper.deleteById(id);
        return result > 0;
    }

    @Override
    public boolean increCount(String key) {
        key = StringUtils.remove(key, CommonConstants.OSS_URL);
        int result = ossService.increCount(key);
        return result > 0;
    }

    @Override
    public boolean decreCount(String key) {
        key = StringUtils.remove(key, CommonConstants.OSS_URL);
        int result = ossService.decreCount(key);
        return result > 0;
    }
}
